<?php 
$pageName=basename($_SERVER['REQUEST_URI']);
if($_GET['date']){
	$date = date('Y-m-d',strtotime($_GET['date']));
}else{
	$date = date('Y-m-d');
}

$week_first = date('Y-m-d', strtotime($date)-86400*date('w',strtotime($date))+(date('w',strtotime($date))>0?86400:-6*86400));
$week_last = date('Y-m-d', strtotime($week_first)+86400*7);

$time_array = array(
  	1=>'00:00',
	2=>'00:30',
	3=>'01:00',
	4=>'01:30',
	5=>'02:00',
	6=>'02:30',
	7=>'03:00',
	8=>'03:30',
	9=>'04:00',
	10=>'04:30',
	11=>'05:00',
	12=>'05:30',
	13=>'06:00',
	14=>'06:30',
	15=>'07:00',
	16=>'07:30',
	17=>'08:00',
	18=>'08:30',
	19=>'09:00',
	20=>'09:30',
	21=>'10:00',
	22=>'10:30',
	23=>'11:00',
	24=>'11:30',
	25=>'12:00',
	26=>'12:30',
	27=>'13:00',
	28=>'13:30',
	29=>'14:00',
	30=>'14:30',
	31=>'15:00',
	32=>'15:30',
	33=>'16:00',
	34=>'16:30',
	35=>'17:00',
	36=>'17:30',
	37=>'18:00',
	38=>'18:30',
	39=>'19:00',
	40=>'19:30',
	41=>'20:00',
	42=>'20:30',
	43=>'21:00',
	44=>'21:30',
	45=>'22:00',
	46=>'22:30',
	47=>'23:00',
	48=>'23:30',
);
$swim = 'swim';
$ice = 'ice-skate';
$exercise = 'exercise';
?>
<div class="swim-contract-banner" <?php if($_GET['date']){echo 'style="display:none;"';}?>>
  <?php if($pageName == 'swim'):?>
      <img src="<?php echo $this->getSkinUrl()?>images/swimming-price.png"/>
  <?php elseif($pageName == 'ice-skate'):?>
      <img src="<?php echo $this->getSkinUrl()?>images/ice-skate-price.png"/>
  <?php elseif($pageName == 'exercise'):?>
      <img src="<?php echo $this->getSkinUrl()?>images/exercise-price.png"/>
  <?php endif;?>
</div>
        <!--swimming-price.png-->
        <div id="swim-timetable" class="swim-price" <?php if($_GET['date']){echo 'style="display:block;"';}?>>
          
          <?php if(preg_match("/{$swim}/",$pageName)):?>
               <h1 class="s-t">SWIMMING PRICES, SESSION & OPENING TIMES</h1>
          <?php elseif(preg_match("/{$ice}/",$pageName)):?>
               <h1 class="s-t">ICE SKATING PRICES, SESSION & OPENING TIMES</h1>
          <?php elseif(preg_match("/{$exercise}/",$pageName)):?>
               <h1 class="s-t">EXERCISE PRICES, CLASSES & OPENING TIMES</h1>
          <?php endif;?>
          <h2 class="s-t-d">Roll over different sessions to find out more information such as prices etc, You can also drag the timetable left or right</h2>
          <div class="date-box">
            <h1 class="date-text">Show me the timetable for the following date:</h1>
            <form action="#">
            <div style="text-align: left;" class="moni_s nav_bellow_search swim-day" onclick="CoLeeSelect2(this)" tabindex="10" id="">
              <input type="text" id="swim-date-day" name="" readonly="readonly" class="select1" value="<?php echo date('d',strtotime($date));?>">
              <ul id="swim-day" class="Option" style="display: none;">
              	<?php 
              	for ($i=1;$i<=date('t',strtotime($date));$i++){
              		echo '<li id="d-'.$i.'" class="" riqiday=""><span>'.$i.'</span></li>';
              	}
              	?>
              </ul>
            </div>
            <div style="text-align: left;" class="moni_s nav_bellow_search swim-year" onclick="CoLeeSelect2(this)" tabindex="10" id="">
              <input type="text" id="swim-date-year-month" name="" readonly="readonly" class="select1" value="<?php echo date('F Y',strtotime($date));?>">
              <input type="hidden" id="swim-date-year-month-value" name="" value="<?php echo date('Y-m',strtotime($date));?>">
              <ul id="swim-month-year" class="Option" style="display: none;">
                <?php 
                $year = date('Y',strtotime($date));
                for ($i=1;$i<=12;$i++){
                	$_date_int = strtotime($year.'-'.$i.'-1');
                	echo '<li id="ym-'.date('Y-m',$_date_int).'-'.date('t',$_date_int).'" riqi='.date('Y-m',$_date_int).' class=""><span>'.date('F Y',$_date_int).'</span></li>';
                }
                ?>
              </ul>
            </div>
            
            </form>
            
            <div class="calendar-ico"> <img src="<?php echo $this->getSkinUrl()?>images/calendar-ico.png"/>
              <div class="calculator_box">
                <div class="closebt"><a>X</a></div>
                <table id="pop_calendar" class="pop_calendar" border="0" cellpadding="0" cellspacing="0">
                  <tbody>
                    <tr>
                      <td id="cc-timetable"></td>
                    </tr>
                  </tbody>
                </table>
              </div>
              <script type="text/javascript">	
var booked_mot = new Array();
var booked_service=new Array();
var mot_or_book;
</script>
              <script language="javascript" type="text/javascript" src="<?php echo $this->getSkinUrl()?>js/dates-timetable.js"></script>
            </div>
          </div>
          <div class="clearfloat"></div>
          <div id="time-bigbg" ></div>
          <div class="timepanel">
            <input type="hidden" id="help_focus" value=""/>
            <div class="week-panel">
            <?php 
            for($i=1;$i<=7;$i++){
				$_date = date('Y-m-d',strtotime($week_first)+(($i-1)*86400));
				echo '
				<div class="week-one"';
				if($_GET['date'] && $date==$_date){
					echo ' id="week_clicked_day"';
				}
				echo '><span>'.date('l',strtotime($_date)).'</span>
                	<div class="week-num">'.date('d',strtotime($_date)).'</div>
              	</div>';
            }
            ?>
            </div>
            <div class="time-table">
            <script src="<?php echo $this->getSkinUrl()?>js/dom-drag.js"></script>
              <div id="time-inner-table" class="time-inner">
                <div class="time"><img src="<?php echo $this->getSkinUrl()?>images/swim-price-time-bar.png"/></div>
                <div class="clearfloat"></div>
                <?php 
				$base_td_class[1]='odd';
				$base_td_class[0]='even';
                  
				$cats = Mage::getSingleton('features/cat');
				$now_catid= $cats->getCatId();
				if(!$now_catid){
					$now_catid=1;
				}

				$popup_data = array();
				for($i=1;$i<=7;$i++){
					$_date = date('Y-m-d',strtotime($week_first)+(($i-1)*86400));
					
					$_collection = Mage::getModel('timetables/timetables')->getCollection()
					->addStoreFilter(Mage::app()->getStore()->getId())
					->addCatFilter($now_catid)
					->addEnableFilter(1)
					->addAttributeToFilter(" ((thedate = '".$_date."' and enddate is null ) OR (thedate <= '".$_date."' and enddate >= '".$_date."'))")
					->setOrder('starttime', 'asc');
					
					$_table_data=array();
					foreach ($_collection as $_item){
						$_starttime = $_item->getStarttime();
						$_datarow = -1;
						
						if(!isset($_table_data[0][$_starttime])){
							$_datarow = 0;
						}else if(!isset($_table_data[1][$_starttime])){
							$_datarow = 1;
						}
						
						if($_datarow>=0){
							$_endtime = $_item->getEndtime();
							for ($j=$_starttime;$j<$_endtime;$j++){
								$_table_data[$_datarow][$j]['id'] = $_item->getId();
								$_table_data[$_datarow][$j]['title'] = $_item->getTitle();
								$_table_data[$_datarow][$j]['color'] = $_item->getColor();
								//$_table_data[$_datarow][$j]['priceall'] = $_item->getPriceall();
								//$_table_data[$_datarow][$j]['pricecsp'] = $_item->getPricecsp();
								//$_table_data[$_datarow][$j]['content'] = $_item->getPostContent();
								//$_table_data[$_datarow][$j]['starttime'] = $_starttime;
								//$_table_data[$_datarow][$j]['endtime'] = $_endtime;
								
								$popup_data[$_item->getId()]['title'] = $_item->getTitle();
								$popup_data[$_item->getId()]['color'] = $_item->getColor();
								$popup_data[$_item->getId()]['priceall'] = $_item->getPriceall();
								$popup_data[$_item->getId()]['pricecsp'] = $_item->getPricecsp();
								$popup_data[$_item->getId()]['content'] = $_item->getPostContent();
								$popup_data[$_item->getId()]['starttime'] = $_starttime;
								$popup_data[$_item->getId()]['endtime'] = $_endtime;
								$popup_data[$_item->getId()]['thedate'] = $_item->getThedate();
								$popup_data[$_item->getId()]['data1'] = $_item->getData1();
								$popup_data[$_item->getId()]['data2'] = $_item->getData2();
								$popup_data[$_item->getId()]['data3'] = $_item->getData3();
								$popup_data[$_item->getId()]['data4'] = $_item->getData4();
								$popup_data[$_item->getId()]['data5'] = $_item->getData5();
								$popup_data[$_item->getId()]['data6'] = $_item->getData6();
								$popup_data[$_item->getId()]['data7'] = $_item->getData7();
								$popup_data[$_item->getId()]['data8'] = $_item->getData8();
								$popup_data[$_item->getId()]['enddate'] = $_item->getEnddate();
	
							}
						}
						
					}

					echo '
					<div id="'.strtolower(date('l',strtotime($_date))).'-table" class="week-right-table" style="top:'.(($i-1)*35+49).'px;">
                  	<table class="" width="100%" border="0" cellspacing="0" cellpadding="0">
                  	<tr>';
					for ($j=1;$j<=48;$j++){
                  		echo '<td width="27" height="0"></td>';
                  	}
                  	echo '
                  	</tr>
                  	';
                  	
					

					for($_datarow = 0;$_datarow<=1;$_datarow++){
						echo '<tr>';
						for ($j=1;$j<=48;$j++){
							
							if(isset($_table_data[$_datarow][$j]['id'])){
								$_colspan = 1;
								$k=$j+1;
								while (isset($_table_data[$_datarow][$k]['id']) && $_table_data[$_datarow][$k]['id']==$_table_data[$_datarow][$j]['id']){
									$_colspan++;
									$k++;
									$j++;
								}
								echo '<td colspan="'.$_colspan.'" class="'.$_table_data[$_datarow][$j]['color'].'-bg poptag" onclick="onPoptagClick('.$_table_data[$_datarow][$j]['id'].')"><span>'.$_table_data[$_datarow][$j]['title'].'</span></td>';
								
							}else{
								$_class = $base_td_class[$j%2];
	                  			echo '<td class="'.$_class.'">&nbsp;</td>';
							}
	                  		
	                  	}
	                  	echo '</tr>';
					}
                  	
					
                 	echo '
                 	</table>
                	</div>';
                 	
                }
                ?>

              </div>
              <div class="timepanel-shadow"></div>
              
            </div>
          </div>
          	<div id="swim-popup-box-shadow" class="swim-popup-box"></div>
          <?php 
          foreach ($popup_data as $_id=>$_data){
          	?>
            <div id="swim-popup-box-<?php echo $_id?>"  class="swim-popup" style="background-image:url(<?php echo $this->getSkinUrl()?>/images/swim-time-pop-<?php echo $_data['color']?>.png)">
	               <div class="swim-popup-inner"> <a class="close-bt" >X</a>
	                <h2><?php echo $_data['title']?></h2>
	                <div class="p-con">
	                  <div id="help-div-<?php echo $_id?>">
	                    <h1>Session Prices</h1>
	                    <?php 
	                    $detail_str = "";
	                    
           				if($_data['priceall']){
	                    	$detail_str.= 'All - &pound;'.$_data['priceall'].'<br/>';
	                    }
	                    
           				if($_data['pricecsp']){
	                    	$detail_str.= 'CSP - &pound;'.$_data['pricecsp'].'<br/>';
	                    }
	                    
	                    if($_data['data1']){
	                    	$detail_str.= 'Per Person - &pound;'.$_data['data1'].'<br/>';
	                    }
	                    
         				if($_data['data2']){
	                    	$detail_str.= 'CSP / Leisure Card - &pound;'.$_data['data2'].'<br/>';
	                    }
	                    
          				if($_data['data3']){
	                    	$detail_str.= 'Adult - &pound;'.$_data['data3'].'<br/>';
	                    }
	                    
         				if($_data['data4']){
	                    	$detail_str.= 'Junior - &pound;'.$_data['data4'].'<br/>';
	                    }
	                    
         				if($_data['data5']){
	                    	$detail_str.= '5\'s & Under - &pound;'.$_data['data5'].'<br/>';
	                    }
	                    
        				if($_data['data6']){
	                    	$detail_str.= 'Family - &pound;'.$_data['data6'].'<br/>';
	                    }
	                    
        				if($_data['data7']){
	                    	$detail_str.= 'Under 50\'s - &pound;'.$_data['data7'].' ';
	                    }
	                    
         				if($_data['data8']){
	                    	$detail_str.= 'Over 50\'s - &pound;'.$_data['data8'].' ';
	                    }
	                    if($detail_str){
	                    	echo '<h5>'.$detail_str.'</h5>';
	                    }
	                    ?>
	                    <p><?php echo $_data['content']?></p>
	                    <h3><?php echo $time_array[$_data['starttime']]?> - <?php echo $time_array[$_data['endtime']]?>, <?php echo date('D',strtotime($_data['thedate'])); if($_data['enddate']){ echo ' - '.date('D',strtotime($_data['enddate']));}?></h3>
	                  </div>
	                </div>
	              </div>
	            </div>
          	<?php 
          }
          ?>
          
        </div>
        <script language="javascript" type="text/javascript">
	      <!--
		       jQuery(document).ready( function($){
	
     $("body").live("keydown",function (e){
		  var key = e.which;
          if(key==13){
			  window.location.href="?date="+$("#swim-date-year-month-value").val()+"-"+$("#swim-date-day").val();
		  }
		  
		 })

	
    $("#time-inner-table").css('left','-438px').css('top','4px');
	$(".swim-contract-banner > img").click(function(){
				$("#swim-timetable").show("slow");
				$(".swim-contract-banner").hide("slow");	
				
					  
		});
	$("#swim-timetable > .s-t, #swim-timetable > .s-t-d").click(function(){
				$("#swim-timetable").hide("slow");
				$(".swim-contract-banner").show("slow");									
		});
	$(".week-panel  .week-one").click(function(){
											   
	jQuery("#time-bigbg").show("slow");
			jQuery("#time-bigbg").bind('click',function(){jQuery("#swim-popup-box-"+temp_id).hide("slow");jQuery("#swim-popup-box-shadow").hide("slow");jQuery("#time-bigbg").hide("slow");                jQuery(".timepanel-shadow").hide("slow");});
				$dome("swim-date-day").value = $(this).find(".week-num").html();
	            $(".week-panel  .week-one").removeClass("week-one-click");
				$(this).addClass("week-one-click");
				//$(this).find(".week-num").empty();
				//$(this).find(".week-num").append($(".swim-price #swim-date-day").val());
				$(".week-right-table").css("z-index","1");
				var week_one = $(this).find("span").html();
				if( week_one == "Monday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 -35px");
					$("#monday-table").css("z-index","11");
					
				} else if( week_one == "Tuesday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 0px");
					$("#tuesday-table").css("z-index","11");
					
				} else if( week_one == "Wednesday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 35px");
					$("#wednesday-table").css("z-index","11");
					
				} else if( week_one == "Thursday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 71px");
					$("#thursday-table").css("z-index","11");
					
				} else if( week_one == "Friday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 105px");
					$("#friday-table").css("z-index","11");
					
				} else if( week_one == "Saturday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 140px");
					$("#saturday-table").css("z-index","11");
				}else if( week_one == "Sunday"){
					$(".timepanel-shadow").show();
					$(".timepanel-shadow").css("z-index","10").css("background-position","0 175px");
					$("#sunday-table").css("z-index","11");
				}
		    			
	$("#swim-timetable").blur(function(){
						   
				  })
		
	    });
	
	$(".calendar-ico > img").click(function(){
		    $(".calendar-ico > .calculator_box").toggle("slow");						  
		});  
	$(".calculator_box .closebt").click(function(){
			$(".calendar-ico > .calculator_box").toggle("slow");									  
		});
	

/**************Swimming Time Panel ****************/
			   });
		  -->
	   </script>
	   
<script language="javascript">
<!--
var temp_id ='';
function onPoptagClick(id){
	temp_id = id;
    jQuery("#swim-popup-box-shadow").show("slow");
	jQuery("#swim-popup-box-"+id).show("slow");
	jQuery("#time-bigbg").show("slow");
	jQuery("#swim-popup-box-"+id+" .close-bt").bind('click',function(){jQuery("#swim-popup-box-"+id).hide("slow");jQuery("#swim-popup-box-shadow").hide("slow");});
	jQuery("#swim-popup-box-shadow").bind('click',function(){jQuery("#swim-popup-box-"+temp_id).hide("slow");jQuery("#swim-popup-box-shadow").hide("slow");});
	jQuery("#time-bigbg").bind('click',function(){jQuery("#swim-popup-box-"+temp_id).hide("slow");jQuery("#swim-popup-box-shadow").hide("slow");jQuery("#time-bigbg").hide("slow");jQuery(".timepanel-shadow").hide("slow");});
	t_height = parseInt(jQuery("#swim-popup-box-"+id).find(".p-con > div").height());
	if(t_height > 196)jQuery("#swim-popup-box-"+id).find(".p-con").css("overflow-y","scroll");
	   else jQuery("#swim-popup-box-"+id).find(".p-con").css("overflow-y","hidden");
}

function dateclicked(y,m,d){
	window.location.href="?date="+y+"-"+m+"-"+d;
}

jQuery(document).ready( function($){
	var aThumb = document.getElementById("time-inner-table");
	if(aThumb!=null){
		Drag.init(aThumb, null, -800, 0, 0, 4);// ���һ����top����
	}
	
	if(document.getElementById('week_clicked_day')!=null){
		jQuery('#week_clicked_day').click();
	}
});
//-->
</script>